using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVAEXCL
    {
        public DataRow Convert2VAEXCL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVAEXCL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VAXMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VAXLFDNR"] = " ".PadRight(8 ); 
         dwReturn["VAXAENZL"] = " ".PadRight(0 ); 
         dwReturn["VAXAENB"] = " ".PadRight(8 ); 
         dwReturn["VAXAEND"] = " ".PadRight(0 ); 
         dwReturn["VAXNEUB"] = " ".PadRight(8 ); 
         dwReturn["VAXNEUD"] = " ".PadRight(0 ); 
         dwReturn["VAXKOLL"] = " ".PadRight(5 ); 
         dwReturn["VAXART"] = " ".PadRight(24 ); 
         dwReturn["VAXFARBE"] = " ".PadRight(10 ); 
         dwReturn["VAXDESS"] = " ".PadRight(10 ); 
         dwReturn["VAXCOL"] = " ".PadRight(10 ); 
         dwReturn["VAXWR"] = " ".PadRight(2 ); 
         dwReturn["VAXLAND"] = " ".PadRight(3 ); 
         dwReturn["VAXVERPART"] = " ".PadRight(3 ); 
         dwReturn["VAXABNGRP"] = " ".PadRight(3 ); 
         dwReturn["VAXKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VAXVB"] = " ".PadRight(3 ); 
         dwReturn["VAXVG"] = " ".PadRight(3 ); 
         dwReturn["VAXVERBKZ"] = " ".PadRight(1 ); 
         dwReturn["VAXSPERRAB"] = " ".PadRight(0 ); 
         dwReturn["VAXSPERRBIS"] = " ".PadRight(0 ); 
         dwReturn["VAXBEM"] = " ".PadRight(60 ); 
         dwReturn["VAXKDDESS"] = " ".PadRight(1 ); 
         dwReturn["VAXFILLER"] = " ".PadRight(110 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVAEXCL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVAEXCL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVAEXCL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVAEXCL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVAEXCL(dwLocal, ITXDBVERSION);
            }
            UpdateVAEXCL(dwLocal);
        }
        public void InsertVAEXCL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VAEXCL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVAEXCL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VAEXCL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VAEXCL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VAEXCL";
            Return = Result;
            return Return;
        }
        public void DeleteVAEXCL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VAEXCL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVAEXCL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VAEXCL SET "
                    +"VAXMANDANT= :VAXMANDANT,"
                    +"VAXLFDNR= :VAXLFDNR,"
                    +"VAXAENZL= :VAXAENZL,"
                    +"VAXAENB= :VAXAENB,"
                    +"VAXAEND= :VAXAEND,"
                    +"VAXNEUB= :VAXNEUB,"
                    +"VAXNEUD= :VAXNEUD,"
                    +"VAXKOLL= :VAXKOLL,"
                    +"VAXART= :VAXART,"
                    +"VAXFARBE= :VAXFARBE,"
                    +"VAXDESS= :VAXDESS,"
                    +"VAXCOL= :VAXCOL,"
                    +"VAXWR= :VAXWR,"
                    +"VAXLAND= :VAXLAND,"
                    +"VAXVERPART= :VAXVERPART,"
                    +"VAXABNGRP= :VAXABNGRP,"
                    +"VAXKUNDNR= :VAXKUNDNR,"
                    +"VAXVB= :VAXVB,"
                    +"VAXVG= :VAXVG,"
                    +"VAXVERBKZ= :VAXVERBKZ,"
                    +"VAXSPERRAB= :VAXSPERRAB,"
                    +"VAXSPERRBIS= :VAXSPERRBIS,"
                    +"VAXBEM= :VAXBEM,"
                    +"VAXKDDESS= :VAXKDDESS,"
                    +"VAXFILLER= :VAXFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VAXMANDANT", OracleType.NVarChar).Value = dwData["VAXMANDANT"].ToString(); 
          or1.Parameters.Add("VAXLFDNR", OracleType.NVarChar).Value = dwData["VAXLFDNR"].ToString(); 
          or1.Parameters.Add("VAXAENZL", OracleType.NVarChar).Value = dwData["VAXAENZL"].ToString(); 
          or1.Parameters.Add("VAXAENB", OracleType.NVarChar).Value = dwData["VAXAENB"].ToString(); 
          or1.Parameters.Add("VAXAEND", OracleType.NVarChar).Value = dwData["VAXAEND"].ToString(); 
          or1.Parameters.Add("VAXNEUB", OracleType.NVarChar).Value = dwData["VAXNEUB"].ToString(); 
          or1.Parameters.Add("VAXNEUD", OracleType.NVarChar).Value = dwData["VAXNEUD"].ToString(); 
          or1.Parameters.Add("VAXKOLL", OracleType.NVarChar).Value = dwData["VAXKOLL"].ToString(); 
          or1.Parameters.Add("VAXART", OracleType.NVarChar).Value = dwData["VAXART"].ToString(); 
          or1.Parameters.Add("VAXFARBE", OracleType.NVarChar).Value = dwData["VAXFARBE"].ToString(); 
          or1.Parameters.Add("VAXDESS", OracleType.NVarChar).Value = dwData["VAXDESS"].ToString(); 
          or1.Parameters.Add("VAXCOL", OracleType.NVarChar).Value = dwData["VAXCOL"].ToString(); 
          or1.Parameters.Add("VAXWR", OracleType.NVarChar).Value = dwData["VAXWR"].ToString(); 
          or1.Parameters.Add("VAXLAND", OracleType.NVarChar).Value = dwData["VAXLAND"].ToString(); 
          or1.Parameters.Add("VAXVERPART", OracleType.NVarChar).Value = dwData["VAXVERPART"].ToString(); 
          or1.Parameters.Add("VAXABNGRP", OracleType.NVarChar).Value = dwData["VAXABNGRP"].ToString(); 
          or1.Parameters.Add("VAXKUNDNR", OracleType.NVarChar).Value = dwData["VAXKUNDNR"].ToString(); 
          or1.Parameters.Add("VAXVB", OracleType.NVarChar).Value = dwData["VAXVB"].ToString(); 
          or1.Parameters.Add("VAXVG", OracleType.NVarChar).Value = dwData["VAXVG"].ToString(); 
          or1.Parameters.Add("VAXVERBKZ", OracleType.NVarChar).Value = dwData["VAXVERBKZ"].ToString(); 
          or1.Parameters.Add("VAXSPERRAB", OracleType.NVarChar).Value = dwData["VAXSPERRAB"].ToString(); 
          or1.Parameters.Add("VAXSPERRBIS", OracleType.NVarChar).Value = dwData["VAXSPERRBIS"].ToString(); 
          or1.Parameters.Add("VAXBEM", OracleType.NVarChar).Value = dwData["VAXBEM"].ToString(); 
          or1.Parameters.Add("VAXKDDESS", OracleType.NVarChar).Value = dwData["VAXKDDESS"].ToString(); 
          or1.Parameters.Add("VAXFILLER", OracleType.NVarChar).Value = dwData["VAXFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
